<?
//Admin 0.0.6
class sym_admin extends symbiont{
    public function ___main($design=''){
        global $kernel, $sym;
        if($kernel->link->param1!=''){
            $symbiont=$kernel->link->param1;
            $kernel->symbiont_add($symbiont);
            $sym->$symbiont->___admin('');
        }
        else{
            $p=new positions('', 'admin');
            $p->prints();
        }
    }
    public function ___symbionts($design=''){
        if(!$design) $design='symbionts/admin/symbionts';
        $d=new design($design, 'admin', false);
        $symbionts=array();
        
        $this->symbionts='';
        
        $dir=opendir("symbionts");
        while($file=readdir($dir)){
            if(($file!=".")&&($file!="..")&&($file[0]!='.')){
                $config='symbionts/'.$file.'/config.json';
                if(file_exists($config)){
                    $content=file_get_contents($config);
                    $json=json_decode($content);
                    if(isset($json->icon)&&$json->icon){
                        $symbionts[$file]=array();
                        $symbionts[$file]['icon']=$json->icon;
                        $l=new label($json->title);
                        $symbionts[$file]['title']=$l->get();
                    }
                }
            }
        }
        closedir($dir);
        
        $positions='symbionts/admin/positions.json';
        if(file_exists($positions)){
            $content=file_get_contents($positions);
            $json=json_decode($content);
            foreach($json as $s){
                if(isset($symbionts[$s])){
                    $this->symbiont_name=$s;
                    $this->src=$symbionts[$s]['icon'];
                    $this->title=$symbionts[$s]['title'];
                    $this->symbionts.=design::run($this->symbiont);
                    unset($symbionts[$s]);
                }
            }
        }
        
        foreach($symbionts as $key=>$val){
            $this->symbiont_name=$key;
            $this->src=$val['icon'];
            $this->title=$val['title'];
            $this->symbionts.=design::run($this->symbiont);
        }
        
        $d->inc();
    }
    public function ___admin($design=''){
        
    }
    public function ___db_sort($design=''){
        if(isset($_POST['sort'])){
            $json=json_encode($_POST['sort']);
            $file=fopen('symbionts/admin/positions.json', 'w');
            fwrite($file, $json);
        }
    }
}
?>